package com.varian.swagger;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil;
import com.varian.misc.ApplicationStartedCustomizer;
import com.varian.misc.VarianApplicationProperties;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.utils.Constants;
import org.springframework.boot.availability.AvailabilityChangeEvent;
import org.springframework.boot.availability.ReadinessState;

/**
 * @author ben
 * @since 2024/6/22
 */
@RequiredArgsConstructor
public class SwaggerApplicationStarted implements ApplicationStartedCustomizer {

    private final VarianApplicationProperties properties;

    @Override
    public String afterMessage(AvailabilityChangeEvent<ReadinessState> event) {
        return StrUtil.format("Api doc:\n\tip: http://{}:{}{}\n\tlocal: http://{}{}", NetUtil.getLocalhostStr(), properties.getPort(), Constants.DEFAULT_API_DOCS_URL,
                properties.getLocalhost(), Constants.DEFAULT_API_DOCS_URL);
    }
}
